<?php
namespace app\admin\controller;
use app\admin\model\About as AboutModel;
use app\admin\controller\Common;
use think\Db;
class About extends Common
{

    public function lst(){
        $about=new AboutModel();
        if(request()->isPost()){
            $sorts=input('post.');
            foreach ($sorts as $k => $v) {
                Db::query("update bk_about set sort=:sort where id=:id",['sort'=>$v,'id'=>$k]);
            }
            $this->success('更新排序成功！',url('lst'));
            return;
        }
        $artres=db('about')->field('a.*')->alias('a')->order('a.id desc')->paginate(10);
        $this->assign('artres',$artres);
        return view();
    }

    public function add(){
        if(request()->isPost()){
            $data=input('post.');
            $data['time']=time();
            $validate = \think\Loader::validate('About');
            if(!$validate->scene('add')->check($data)){
                $this->error($validate->getError());
            }
            $article=new AboutModel;
            if($article->save($data)){
                $this->success('添加关于页成功',url('lst'));
            }else{
                $this->error('添加关于页失败！');
            }
            return;
        }
      
        return view();
    }

    public function edit(){
        if(request()->isPost()){
            $data=input('post.');
            $validate = \think\Loader::validate('About');
            if(!$validate->scene('edit')->check($data)){
                $this->error($validate->getError());
            }
            $article=new AboutModel;
            $save=$article->update($data);
            if($save){
                $this->success('修改关于页成功！',url('lst'));
            }else{
                $this->error('修改关于页失败！');
            }
            return;
        }
       
        $arts=db('about')->where(array('id'=>input('id')))->find();
        $this->assign('arts',$arts);
        return view();
    }

    public function del(){
        if(AboutModel::destroy(input('id'))){
            $this->success('删除关于页成功！',url('lst'));
        }else{
            $this->error('删除关于页失败！');
        }
    }


 



   

	












}
